import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class InterFace {
    public static void main(String[] args) {
        new InterFace();
    }

    public InterFace() {
        JFrame jFrame = new JFrame("登录界面");
        jFrame.setLayout(new FlowLayout());

        JLabel label = new JLabel();
        label.setText("酒店管理系统");
        label.setBounds(150,40,200,40);
        jFrame.add(label);

        JLabel jLabel1 = new JLabel("账号");
        jLabel1.setBounds(150, 40, 200, 40);

        JTextField jTextField = new JTextField(10);
        JLabel jLabel2 = new JLabel("密码");
        jLabel2.setBounds(150, 40, 200, 40);
        JPasswordField jPasswordField = new JPasswordField(10);
        JButton ok = new JButton("确定");

        jFrame.add(jLabel1);
        jFrame.add(jTextField);
        jFrame.add(jLabel2);
        jFrame.add(jPasswordField);
        jFrame.add(ok);

        ok.addActionListener(new ActionListener() {//给确定按钮添加事件
            @Override
            public void actionPerformed(ActionEvent e) {
                String jtext = jTextField.getText();//得到账号
                char[] ch = jPasswordField.getPassword();//得到密码
                String jpass = new String(ch);//得到的密码转成String类型
                if (jtext.equals("1") & jpass.equals("1")) {//判断密码是否正确
                    System.out.println("密码正确，进入酒店管理系统");
                    new SystemDemo();
                } else {
                    JDialog dialog = new JDialog(jFrame, "账号或者密码错误！", true);
                    dialog.setBounds(750, 450, 300, 50);
                    dialog.setVisible(true);
                    jTextField.setText("");
                    jPasswordField.setText("");
                }
            }
        });
        jFrame.setVisible(true);
        jFrame.setBounds(600, 400, 600, 250);
        //  jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE);
    }
}
